import java.util.*;
public class test {
    //牛客网训练 ACCEPT
    public class Main {
        public static void main(String[] args) {
            Scanner in = new Scanner(System.in);
            int T = in.nextInt();
            while(T-- > 0){
                int n = in.nextInt();
                String s = in.next();
                int len = s.length();
                HashMap<Character,Integer> map = new HashMap<>();
                for(int i = 0;i < len;i++){
                    char c = s.charAt(i);
                    map.put(c,map.getOrDefault(c,0) + 1);
                }
                int min = map.getOrDefault('A',0);
                min = Math.min(map.getOrDefault('C',0) / 2,min);
                min = Math.min(map.getOrDefault('E',0),min);
                min = Math.min(map.getOrDefault('P',0),min);
                min = Math.min(map.getOrDefault('T',0),min);
                System.out.println(min);
            }
        }
    }
    //牛客网训练 青蛙阶梯
    public class Main1 {
        public static void main(String[] args) {
            Scanner in = new Scanner(System.in);
            long i = in.nextLong();
            System.out.println(i % 2 == 0 ? i * 2 : i * 2 + 1);
        }
    }
    //牛客网训练 得分训练
    public class Main2 {
        public static void main(String[] args) {
            Scanner scanner = new Scanner(System.in);
            int n = scanner.nextInt();
            int[] arr = new int[n];
            for (int i = 0; i < n; i++) {
                arr[i] = scanner.nextInt();
            }
            double ans = arr[0] + 1;
            for (int i = 1; i < n; i++) {
                ans = Math.min(ans, (double) (arr[i] + 1) / (i + 1));
            }
            System.out.printf("%.10f%n", ans);
        }
    }
    //牛客网训练 悬崖
    public class Main3 {
        public static void main(String[] args) {
            Scanner in = new Scanner(System.in);
            int n = in.nextInt();
            int[] arr1 = new int[n];
            int[] arr2 = new int[n];
            for(int i = 0;i < n;i++){
                int a = in.nextInt();
                int b = in.nextInt();
                arr1[i] = Math.min(a,b);
                arr2[i] = Math.max(a,b);
            }
            int max = Integer.MIN_VALUE;
            for(int i = 1;i < n;i++){
                max = Math.max(max,arr2[i] - arr1[i - 1]);
            }
            System.out.println(max);
        }
    }
}
